class Crawler::Job
  attr_accessor :deadline
  
  def self.create_all(crawler)
    [
      Crawler::SourceMonitorJob.new(crawler),
      Crawler::FetchJob.new(crawler),
      Crawler::TrendJob.new(crawler),
      Crawler::RuleJob.new(crawler)
    ]
  end
  
  def initialize(crawler)
    @crawler = crawler
    update_deadline
  end
  
  def run
    update_deadline
  end
  
  def update_deadline
    @deadline = Time.now + 5.seconds
  end

  # shortcuts for logging different types of events
  def log_info(msg, *args) @crawler.log_event("info", "[#{self.class.name}] #{msg}", *args) end
  def log_warning(msg, *args) @crawler.log_event("warning", "[#{self.class.name}] #{msg}", *args) end
  def log_error(msg, *args) @crawler.log_event("error", "[#{self.class.name}] #{msg}", *args) end

end
